#ifndef __SWF_TAGS__
#define __SWF_TAGS__

#include "primitives.hpp"

namespace swf
{
	struct FileHeader
	{
		uint8_t	sig0, sig1, sig2;
		uint8_t	ver;
		uint32_t length;
		bool_t read( StreamIn & is )
		{
			neednz( is.read(sig0) );
			if( sig0 != 'C' && sig0 != 'F' && sig0 != 'Z' ) 
				return false;
			neednz( is.read(sig1) );
			if( sig1 != 'W' ) return false;
			neednz( is.read(sig2) );
			if( sig2 != 'S' ) return false;
			neednz( is.read(ver) );
			neednz( is.read(length) );
			return true;
		}
	};

	struct FileHeader2
	{
		RECT	 frameSize;
		uint16_t frameRate;
		uint16_t frameCount;
		bool_t read( StreamIn & is )
		{
			neednz( frameSize.read(is) );
			neednz( is.read(frameRate) );
			neednz( is.read(frameCount) );
			return true;
		}
	};

	struct Tag
	{
		uint16_t tag;
		uint32_t length;
		bool_t read( StreamIn & is )
		{
			struct _tag_t 
			{
				uint16_t length:6;
				uint16_t tag:10;
			} tmp;
			neednz( is.read(tmp) );
			tag = tmp.tag;
			if( tmp.length != 0x3F )
			{
				length = tmp.length;
			}
			else
			{
				neednz( is.read(length) );
			}
			return true;
		}
	};

	namespace tag 
	{
		struct FileAttributes
		{
			NB8<1>		Reserved;
			NB8<1>		UseDirectBlit;
			NB8<1>		UseGPU;
			NB8<1>		HasMetadata;
			NB8<1>		ActionScript3;
			NB8<2>		Reserved1;
			NB8<1>		UseNetwork;
			_UI8		Reserved2[3];
			bool_t read( StreamIn & is )
			{
				neednz(Reserved.read(is));
				neednz(UseDirectBlit.read(is));
				neednz(UseGPU.read(is));
				neednz(HasMetadata.read(is));
				neednz(ActionScript3.read(is));
				neednz(Reserved1.read(is));
				neednz(UseNetwork.read(is));
				return ( is.read(Reserved2) );
			}
		};
		struct DoABC
		{
			UI32	Flags;
			STRING	Name;
			bool_t read( StreamIn & is )
			{
				neednz(Flags.read(is));
				neednz(Name.read(is));
				return true;
			}
		};
	};

};


#endif